const jwt = require("jsonwebtoken");
const { PRIVATE_KEY } = require("../app/config");
class AuthController {
  async login(ctx, next) {
    const { id, name, email, cellphone } = ctx.user;
    const token = jwt.sign({ id, name, email, cellphone }, PRIVATE_KEY, {
      expiresIn: 60 * 60 * 24 * 5,
      algorithm: "RS256"
    }, null);
    ctx.body = {
      code: 0,
      status: 200,
      data: {
        id,
        name,
        token,
        msg: "success"
      }
    };
  }
  success(ctx, next) {
    ctx.body = {
      code: 0,
      status: 200,
      data: {
        ...ctx.user
      }
    };
  }
}

module.exports = new AuthController();
